#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    int yu;
    while(1){
        yu = a%b;
        if(yu!=0){
            a = b;
            b = yu;
        }
        else if(yu==0){
            printf("%d",b);
            break;
        }
    }
    return 0;
}